<template>
  <div>
    注册
    <input type="text" placeholder="请输入用户名" v-model="info.name" />
    <input type="text" placeholder="请输入密码" v-model="info.pwd" />
    <button @click="registerto">注册</button>
  </div>
</template>

<script lang="ts" setup>
import { register } from "../../api/api";
import { ref } from "vue";
import { useRouter } from "vue-router";

const router = useRouter();
const info = ref({
  name: "",
  pwd: "",
});
const registerto = () => {
  register(info.value.name, info.value.pwd).then((res) => {
    console.log(res);
    if (res.data.code == 0) {
      alert("用户已存在 请重新输入");
    }
    if (res.data.code == 1) {
      alert("注用成功！请登录");
      router.push("/");
    }
  });
};
</script>

<style scoped></style>
